/**
 * @author Jonathan Jung, Timothy Hong, Ronen Adam
 * 
 */

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.net.SocketException;

public class TxEngine {
	private DatagramSocket sock;
	private Port parent;

	public TxEngine(DatagramSocket ds, Port parent) {
		sock = ds;
		this.parent = parent;
	}

	/**
	 * Packages and IPDatagram into an Ethernet Frame
	 * 
	 * @param message
	 * @throws SocketException
	 */
	public void transmit(IPv4Datagram message) throws SocketException {
		System.out.println("********Transmission********");

		SocketAddress destAddress = sock.getRemoteSocketAddress();
		byte[] type = { 0, 0 };
		EthernetFrame packageDatagram = new EthernetFrame(parent.getDesMac(),
				parent.getSrcMac(), type, message.getBytes());
		DatagramPacket sendPacket;

		sendPacket = new DatagramPacket(packageDatagram.toByte(),
				packageDatagram.toByte().length, destAddress);

		// Used for Testing purposes
		System.out.print(message);

	}

}